package com.yqg.protection.utils;

import com.github.qcloudsms.SmsSingleSender;
import com.github.qcloudsms.SmsSingleSenderResult;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class SmsUtil {
    private final static int appid = 1400965277;
    private final static String appkey = "AKIDZDpKhw44umYAaqwteFezA9yb6SddQ2Sh";

    public static String sendMessage(int templateId, String smsSign, String phoneNumber, String[] replacedValues) {

        String status = "";
        //给手机发送短信
        //1.腾讯云自己项目的AppID
        //2.腾讯云自己项目的Appkey
        //3  短信的模板ID templateId
        //4  签名的名字  smsSign
        //5 .给谁发 phoneNumber
        //String phoneNumber = "17671775xxx";
        //6. 验证码：手动不随机验证码 最多六位数 只能是数字
        // String[] params = {"876032"};
        //7.发送短信对象
        SmsSingleSender ssender = new SmsSingleSender(appid, appkey);

        //地区，电话，模板ID，验证码，签名
        try {
            SmsSingleSenderResult result = ssender.sendWithParam("86", phoneNumber, templateId, replacedValues, smsSign, "", "");
            status = result.errMsg;
            log.info("sms send status,template id [{}],phone is [{}],status is [{}] ", templateId, phoneNumber, status);
        } catch (Exception e) {
            log.info("sms send status,template id [{}],phone is [{}],status is [{}] ", templateId, phoneNumber, status, e);
        }
        return status;  // 此处的status只有发送成功是"OK"
    }
}
